package org.infodavid.common.model;

import java.beans.Transient;
import java.security.Principal;
import java.util.Locale;
import java.util.Map;

import org.infodavid.common.model.IPerson.EPersonTitle;
import org.infodavid.common.model.components.IEMail;
import org.infodavid.common.persistence.ICommented;
import org.infodavid.common.persistence.IDataObject;
import org.infodavid.common.persistence.ILockable;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

/**
 * The Interface IUser.
 */
public interface IUser extends IDataObject<Long>, Principal, ICommented, ILockable, IGenericObject {

  /** The Constant DEFAULT_PASSWORD. */
  String DEFAULT_PASSWORD = "change_on_install";

  /** The Constant ADMINISTRATOR. */
  String ADMINISTRATOR = "admin";

  /** The Constant NOBODY. */
  String NOBODY = "nobody";

  /** The Constant SYSTEM. */
  String SYSTEM = "sys";

  /** The default administrator email. */
  String DEFAULT_ADMINISTRATOR_EMAIL = "root@localhost";

  /** The constant LOCAL_BEAN_JNDI_NAME. */
  String LOCAL_BEAN_JNDI_NAME = "IUser/local";

  /** The PASSWORD. */
  String PASSWORD = "password";

  /** The LAST_IP. */
  String LAST_IP = "lastIP";

  /** The GROUPS. */
  String GROUPS = "groups";

  /** The PRIMARY_GROUP. */
  String PRIMARY_GROUP = "primaryGroup";

  /** The TIME_ZONE. */
  String TIME_ZONE = "timeZone";

  /** The LOCALE. */
  String LOCALE = "locale";

  /** The PERSON. */
  String PERSON = "person";

  /** The CONNECTIONS_COUNT. */
  String CONNECTIONS_COUNT = "connectionsCount";

  /** The EXPIRATION_DATE. */
  String EXPIRATION_DATE = "expirationDate";

  /** The LAST_CONNECTION_DATE. */
  String LAST_CONNECTION_DATE = "lastConnectionDate";

  /** The LOCKED. */
  String LOCKED = "locked";

  /** The HIGHEST_ROLE. */
  String HIGHEST_ROLE = "highestRole";

  /** The constant MAX_LENGTH_LAST_IP. */
  int MAX_LENGTH_LAST_IP = 15;

  /** The constant MAX_LENGTH_PASSWORD. */
  int MAX_LENGTH_PASSWORD = 32;

  /** The EMAIL. */
  String EMAIL = "email";

  /** The FIRSTNAME. */
  String FIRST_NAME = IPerson.FIRST_NAME;

  /** The ID. */
  String ID = "userKey";

  /** The LASTNAME. */
  String LAST_NAME = "lastName";

  /** The constant MAX_LENGTH_FIRST_NAME. */
  int MAX_LENGTH_FIRST_NAME = 64;

  /** The constant MAX_LENGTH_LAST_NAME. */
  int MAX_LENGTH_LAST_NAME = 96;

  /** The constant MAX_LENGTH_LOGIN_NAME. */
  int MAX_LENGTH_LOGIN_NAME = 32;

  /** The constant MAX_LENGTH_PSEUDONYM. */
  int MAX_LENGTH_PSEUDONYM = 32;

  /** The PSEUDONYM. */
  String PSEUDONYM = "pseudo";

  /** The TITLE. */
  String TITLE = IPerson.TITLE;

  /** The USER. */
  String USER = "user";

  /**
   * Gets the last IP address.
   * @return the last address
   */
  String getLastIP();

  /**
   * Gets the groups. Primary group is the first of the list.The primary group is a included in this
   * map of groups.
   * @return the groups
   */
  Map<String,IUserGroup> getGroups();

  /**
   * Adds the group.
   * @param value the value
   */
  void addGroup(IUserGroup value);

  /**
   * Removes the group.
   * @param value the value
   * @return true, if successful
   */
  boolean removeGroup(IUserGroup value);

  /**
   * Gets the primary group. The primary group is a included in the map of groups.
   * @return the group
   */
  IUserGroup getPrimaryGroup();

  /**
   * Gets the person.
   * @return the person or null
   */
  IPerson getPerson();

  /**
   * Gets the highest role.
   * @return the highest role
   */
  @Transient
  IUserGroup.EUserRole getHighestRole();

  /**
   * Sets the primary group. The primary group is a included in the map of groups.
   * @param value the primary group
   */
  void setPrimaryGroup(IUserGroup value);

  /**
   * Sets the person.
   * @param value the person
   */
  void setPerson(IPerson value);

  /**
   * Sets the highest role.
   * @param value the new highest role
   */
  void setHighestRole(IUserGroup.EUserRole value);

  /**
   * Gets the password.
   * @return the password
   */
  String getPassword();

  /**
   * Sets the last IP address.
   * @param value the address
   */
  void setLastIP(String value);

  /**
   * Sets the password.
   * @param value the value
   */
  void setPassword(String value);

  /**
   * Gets the time zone.
   * @return the time zone
   */
  DateTimeZone getTimeZone();

  /**
   * Sets the time zone.
   * @param value the new time zone
   */
  void setTimeZone(DateTimeZone value);

  /**
   * Gets the locale.
   * @return the locale
   */
  Locale getLocale();

  /**
   * Sets the locale.
   * @param value the new locale
   */
  void setLocale(Locale value);

  /**
   * Gets the connections count.
   * @return the connections count
   */
  long getConnectionsCount();

  /**
   * Gets the expiration date.
   * @return the expiration date
   */
  DateTime getExpirationDate();

  /**
   * Gets the last connection date.
   * @return the last connection date
   */
  DateTime getLastConnectionDate();

  /**
   * Checks if is expired according to the current date and the expiration one.
   * @return true, if checks if is expired
   */
  boolean isExpired();

  /**
   * Sets the connections count.
   * @param value the value
   */
  void setConnectionsCount(long value);

  /**
   * Sets the expiration date.
   * @param value the date
   */
  void setExpirationDate(DateTime value);

  /**
   * Sets the last connection date.
   * @param value the date
   */
  void setLastConnectionDate(DateTime value);

  /**
   * Gets the user email.
   * @return the email
   */
  IEMail getEmail();

  /**
   * Gets the first name.
   * @return the first name
   */
  String getFirstName();

  /**
   * Gets the last name.
   * @return the last name
   */
  String getLastName();

  /**
   * Gets the login name.
   * @return the login name
   */
  String getLoginName();

  /**
   * Gets the user pseudonym.
   * @return the pseudonym
   */
  String getPseudonym();

  /**
   * Gets the title.
   * @return the title
   */
  EPersonTitle getTitle();

  /**
   * Sets the email.
   * @param value email
   */
  void setEmail(IEMail value);

  /**
   * Sets the first name.
   * @param value the value
   */
  void setFirstName(String value);

  /**
   * Sets the last name.
   * @param value the value
   */
  void setLastName(String value);

  /**
   * Sets the login name.
   * @param value the value
   */
  void setLoginName(String value);

  /**
   * Sets the pseudonym.
   * @param value pseudonym
   */
  void setPseudonym(String value);

  /**
   * Sets the title.
   * @param value the value
   */
  void setTitle(EPersonTitle value);

  /**
   * Checks if is locked.
   * @return true, if checks if is locked
   */
  boolean isLocked();

  /**
   * Sets the locked.
   * @param flag the flag
   */
  void setLocked(boolean flag);
}
